<template>
	<view class="container">
		<navBar isBack title="店铺地址"></navBar>
		<view class="title">
			<view class="title-text">所在地区</view>
			<view  @tap="handleAddress" class="df-bt title-input">
				<input type="text" v-model="selectArea" disabled="true" placeholder="点击选择" placeholder-style="font-size:24rpx;text-align:right;color:#D8D8D8"/>
				<text class="iconfont icon-jinru"></text>
			</view>
			
		</view>
		<view class="address">
			<view class="name">
				详细地址
			</view>
			<view class="textarea">
			     <textarea v-model="address" placeholder-style="color:#D8D8D8" placeholder="道路、门牌号、楼栋号等"/>
			</view>
		</view>	
		<u-picker mode="region" v-model="addressShow" @confirm="pickAddress" :area-code='areaCode'></u-picker>
		<!-- <u-select v-model="show" mode="mutil-column-auto" :list="list" @confirm="confirm"></u-select> -->
			<u-button type="warning" shape="circle" @click="backNav">确定</u-button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				addressShow:false,
				areaCode:[],
				selectArea:'', //地区
				address:'', //详细地址
				province:'',
				city:'',
				area:'',
				provinceId:null,
				cityId:null,
				areaId:null,
				list:[],
				index:'',
				array:[],
				
			}
		},
		onLoad() {
			this.getStoreInfo()
		},
		methods:{
			// 获取省市区
			// 获取省份列表
			getProvice(){
				this.$api.getProviceList().then(res=>{
					console.log(res,'省份列表')
					if(res.code==1){
						this.selectList = res.data?res.data:[]
					}
				})
			},
			// 获取城市
			getCity(){
				this.$api.getCityList({province_id:this.province_id}).then(res=>{
					console.log(res,'城市列表')
					if(res.code==1){
						this.selectList = res.data?res.data:[]
					}
				})
			},
			// 获取县区
			getDistrict(){
				this.$api.getDistrictList({city_id:this.city_id}).then(res=>{
					console.log(res,'县区列表')
					if(res.code==1){
						this.selectList = res.data?res.data:[]
					}
				})
			},
			bindPickerChange(e){
				console.log(e,'地区选择')
			},
			
			
			// 获取店铺信息
			getStoreInfo(){
				let store_id = this.$store.state.index.sid
				this.$api.store_storeDetail({store_id}).then(res=>{
					if(res.code==1){
						console.log(res,'选择地址店铺详情')
						// this.storeInfo = res.data?res.data:{}
						this.address = res.data.address
						// 地址弹框默认
						
						let province = res.data.province?res.data.province.toString().substr(0,2):'11'
						let city = res.data.city?res.data.city.toString().substr(0,4):'1101'
						let area = res.data.area?res.data.area.toString():'110101'
						this.areaCode = [province,city,area]
						
						this.provinceId = res.data.province
						this.cityId = res.data.city
						this.areaId = res.data.area
						
						this.province = res.data.province_name
						this.city = res.data.city_name
						this.area = res.data.area_name
						this.selectArea = res.data.province_name+res.data.city_name+res.data.area_name
						
					}
				})
			},
			handleAddress(){
				this.addressShow = true
			},
			// 地址弹框的确定
			pickAddress(e){
				console.log(e,'地址弹框')
				this.provinceId = e.province.value+'0000'
				this.cityId = e.city.value+'00'
				this.areaId = e.area.value
				console.log(this.provinceId,this.cityId,this.areaId,'----')
				
				this.province = e.province.label
				this.city = e.city.label
				this.area = e.area.label
				this.selectArea = e.province.label+e.city.label+e.area.label
			},
			
			// 确定按钮
			backNav(){
				let nowArea = {
					provinceId:this.provinceId,
					cityId:this.cityId,
					areaId:this.areaId,
					province:this.province,
					city:this.city,
					area:this.area,
					address:this.address
				}
				console.log(nowArea,'当前选择的地区')
				let pages = getCurrentPages();  //获取所有页面栈实例列表
				console.log(pages)
				let nowPage = pages[ pages.length - 1];  //当前页页面实例
				let prevPage = pages[ pages.length - 2 ];  //上一页页面实例
				console.log(prevPage)
				prevPage.$vm.allArea = nowArea;
				uni.navigateBack({
					delta: 1
				});
			}
		}
	}
</script>

<style lang="less" scoped>
	.container{
		width: 100%;
		padding: 112rpx 56rpx;
		.title-text{
			font-size: 32rpx;
			font-family: PingFang SC;
			font-weight: 500;
			line-height: 32rpx;
			color: #0A0605;
			margin-bottom: 28rpx;
		}
		.title-input{
			height: 96rpx;
			background: #F5F5F5;
			border-radius: 8rpx;
			margin-bottom: 60rpx;
		}
		.name{
			font-size: 32rpx;
			font-family: PingFang SC;
			font-weight: 500;
			line-height: 32rpx;
			color: #0A0605;
			margin-bottom: 28rpx;
		}
		.textaree{
			height: 212rpx;
			border-radius: 8rpx;
			background: #f5f5f5;
			margin-bottom: 60rpx;
		}
	}
</style>
